#include "chatserver.hpp"
#include "chatservice.hpp"
#include <string>
#include <iostream>
#include "json.hpp"
#include <signal.h>
using namespace std;
using json = nlohmann::json;
// 服务器异常中断后：Ctrl+c结束后，重置user的状态信息
void restHandler(int signum)
{
    cout<<"重置user表state信息"<<endl;
    Chatservice::instance()->reset();
    exit(0);
}
int main(int argc,char* argv[])
{
    if(argc!=3)
    {
        cerr << "command invalid! example: ./server ip port" << endl;
        exit(-1);
    }
    char* ip=argv[1];
    int port=atoi(argv[2]);

    signal(SIGINT, restHandler);
    EventLoop loop;
    InetAddress addr(ip, port);
    ChatServer server(&loop, addr, "ChatServer");
    server.start();
    loop.loop();
    return 0;
}
